A picture remembers color numbers and a palette says which color each number is, so one picture can be drawn in many sets of colors - for one instance, one background, the room's tiles, text, particles or the zoomable background.
A picture on the Game Boy Advance does not store colors. It stores numbers. Each pixel says "I am color number 3", and a separate list says what color number 3 is. That list is a palette. A 16-color palette is a list of 16 colors; the picture just points into it.
That is the trick behind every "same enemy, different color" in a game. You draw the enemy once. You make a second palette with the same 16 places filled with different colors. Draw the enemy with the second palette and it looks new, and the picture only takes up room once.
Palettes are things you make in the Paint tab and give a name, like a sprite or a font. A game only carries the palettes it actually uses.
| A palette with | fits |
|---|---|
| 16 colors | sprites, backgrounds, a room's tiles, text and particles |
| 256 colors | the zoomable background, which is drawn with 256 |
Color number 0 is the see-through one in a 16-color picture, so the first color of a palette is not drawn on a sprite.
There is one call for each kind of picture. All six take a palette, and all six take nothing to mean "go back to the picture's own colors".
| Call | Recolors |
|---|---|
sprite_palette | only the instance that calls it |
background_palette | a background you made with background_create |
tile_layer_palette | the floor and walls of the room you are in |
text_palette | the letters draw_text draws |
effect_palette | the particles of an effect |
zoom_background_palette | the room's zoomable background |
// Create event of one enemy out of a crowd
sprite_palette(pal_doc_gold);Only this enemy turns gold. Every other copy of the same object keeps its colors, because the palette belongs to the instance that asked for it.
You can also pick a palette in the editor: the room's Set palette list (Room Editor, Tile Palette, Tilesets), an object's default palette (every new copy starts with it), and a placed copy's own palette. They do the same thing as the calls above. Code that runs later still wins: if your code says sprite_palette(nothing), the copy goes back to its sprite's own colors.
The console can show 16 different palettes for sprites at once, and another 16 for backgrounds. That sounds like plenty, but sprites that look alike share a slot, and sprites that look different do not:
If a seventeenth palette asks for a slot, the game cannot give it one. A development build stops because the console ran out of sprite palettes. A release build keeps going and leaves that picture in its own colors. Use the same palette for more of your things, or show fewer different ones at once.
The Budgets panel counts the palettes a room can show at once. A background picture or a tileset can also be drawn with several palettes side by side, each taking a slot of the same 16 - see One picture, several palettes.
text_palette.background_palette recolors every background made from the same picture that is still showing the same colors. Make two pictures with the same pixels if you need two looks at once.zoom_background_palette.draw_sprite draws the picture you ask for in that picture's own colors. Only draw_self and the automatic drawing wear the instance's palette.